define(function(require, exports, module){

	var requestByAjax = module.exports = function(settings, callback){
		var canceled = false;


        if(_.isUndefined(settings.data))
        {
            settings.data={};
        }

        //如果登录，每次传参代入appKey
        var PSessionId = App.storage.getCookieSession("PSessionId");
        if(!_.isUndefined(PSessionId)){

            PSessionId = PSessionId.PSessionId;

            settings.data.PSessionId = PSessionId;
        }

        //配置ajax heard
        settings.contentType ="application/x-www-form-urlencoded;" +
            "application/json; " +
            "charset=utf-8";


		var xhr = $.ajax(settings);
		xhr.done(function(resp, status, xhr){
			if(!canceled){
				callback("connect", resp);
			}
		});

		xhr.fail(function(xhr, status, errorThrown){
			if(!canceled){
				callback(status);
			}
		});

		var result = {};
		result.cancel = function(){
			canceled = true;
			callback("canceled");
		};
		result.abort = function(){
			xhr.abort();
		};
		return result;
	};

});
